import * as sdk from './fetch';

const controllerName = 'houseController';

/**
 *
 * 查询当前用户的所有房屋
 *
 */
async function findByUserId(params): Promise<BaseResponseString> {
  let result = await sdk.rzpost(
    'house/findByUserId',

    {
      ...params
    },
  );
  return result;
}
/**
 *
 * 根据房屋查询所有住户
 *
 */
async function findByHouseId(params): Promise<BaseResponseString> {
  let result = await sdk.rzpost(
    'userHouse/findByHouseId',

    {
      ...params
    },
  );
  return result;
}
/**
 *
 * 查询所有城市
 *
 */
async function findAllCity(): Promise<BaseResponseString> {
  let result = await sdk.rzpost(
    'community/findAllCity',

    {},
  );
  return result;
}
/**
 *
 * 查询小区列表
 *
 */
async function findCommunityByCity(params): Promise<BaseResponseString> {
  let result = await sdk.rzpost(
    'community/findCommunityByCity',

    {
      ...params
    },
  );
  return result;
}
/**
 *
 * 查询楼栋列表
 *
 */
async function findByCommunityId(params): Promise<BaseResponseString> {
  let result = await sdk.rzpost(
    'building/findByCommunityId',

    {
      ...params
    },
  );
  return result;
}
/**
 *
 * 查询单元列表
 *
 */
async function findByBuildingId(params): Promise<BaseResponseString> {
  let result = await sdk.rzpost(
    'building/findByBuildingId',

    {
      ...params
    },
  );
  return result;
}
/**
 *
 * 查询单元列表
 *
 */
async function findByUnitId(params): Promise<BaseResponseString> {
  let result = await sdk.rzpost(
    'house/findByUnitId',

    {
      ...params
    },
  );
  return result;
}
/**
 *
 * 查询业主信息
 *
 */
async function findHouseByUserId(params): Promise<BaseResponseString> {
  let result = await sdk.rzget(
    `house/findHouseByUserId?phone=${params.phone}&communityId=${params.communityId}`,

    {},
  );
  return result;
}
/**
 *
 * 添加房屋
 *
 */
async function addUserHouse(params): Promise<BaseResponseString> {
  let result = await sdk.rzpost(
    'userHouse/appAdd',

    {
      ...params
    },
  );
  return result;
}
/**
 *
 * 切换房屋
 *
 */
async function updateDefHouse(params): Promise<BaseResponseString> {
  let result = await sdk.rzpost(
    'userHouse/updateDefHouse',

    {
      ...params
    },
  );
  return result;
}
/**
 *
 * 业主审核住户申请:status(1:同意,2:拒绝)
 *
 */
async function houseProve(params): Promise<BaseResponseString> {
  let result = await sdk.rzpost(
    'userHouse/appApprove',

    {
      ...params
    },
  );
  return result;
}
/**
 *
 * 解绑当前房屋、业主删除住户(业主删除住户及自己)
 *
 */
async function unLockHouse(params): Promise<BaseResponseString> {
  let result = await sdk.rzpost(
    'userHouse/unLockHouse',

    {
      ...params
    },
  );
  return result;
}
/**
 *
 * 解绑其他房屋
 *
 */
async function deleteHouse(params): Promise<BaseResponseString> {
  let result = await sdk.rzpost(
    'userHouse/delete',

    {
      ...params
    },
  );
  return result;
}

export default {
  findByUserId,
  findByHouseId,
  findAllCity,
  findCommunityByCity,
  findByCommunityId,
  findHouseByUserId,
  findByBuildingId,
  findByUnitId,
  addUserHouse,
  updateDefHouse,
  houseProve,
  unLockHouse,
  deleteHouse,
};

/**
 * 正常请求返回
 */
export interface BaseResponseString {
  /**
   * 结果码
   */
  code: string;
  /**
   * 内容
   */
  data?: {
    [k: string]: any;
  };
  /**
   * 错误内容
   */
  errorData?: {
    [k: string]: any;
  };
  /**
   * 状态
   */
  success?: boolean;
  /**
   * 消息内容
   */
  message?: string;
  [k: string]: any;
}
